<?php
mysql_connect("d-12602", "root", "") or die(mysql_error());
mysql_select_db("cc_v1") or die(mysql_error());
function updateUserScores(){
	$strQuery = "Select id,currentTeamId from cc_V1.users";
	$result = mysql_query($strQuery);
	while($row = mysql_fetch_assoc($result)){
		echo "<br>ID: ".$row["id"];
		echo "<br>Team: ".$row["currentTeamId"];
		$points=0;
		$strQuery2 = "Select * from cc_V1.team where id = ".$row["currentTeamId"].";";
		$result2 = mysql_query($strQuery2);
		if($result2 && mysql_num_rows($result2)>0){
			while($row2 = mysql_fetch_assoc($result2)){
				foreach ( $row2 as $key => $value ) {
					if(strpos($key, 'Id')>0 && strcasecmp($key,"userId")!=0)
						echo "<br>".$key."=>>".$value; 
					$strQuery3 = "Select points from cc_V1.player where id = $value";
					$result3=mysql_query($strQuery3);
					
					if($result3 && mysql_num_rows($result3)>0){
						$pts=mysql_result($result3,"points");
						echo " Points: ".$pts;
						$points = $points + $pts;      
					}
				}
			}
		}
		$strQuery4 = "<br>"."Update users set score=$points where id=".$row["id"];
		echo $strQuery4;
		mysql_query($strQuery4);
	}
}
?>
